package com.movecar.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

import com.movecar.R;
import com.movecar.widget.CustomProgressDialog;
import com.movecar.widget.ProgressWebView;

/**
 * 活动详情-内置浏览器
 * 
 * @author Zhao.JQ
 * 
 */
public class GroupDetailPaymentWebViewActivity extends Activity implements OnClickListener {

	private CustomProgressDialog progressDialog = null;
	private ProgressWebView mWebView;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.group_detail_payment_webview);
		initView();
	}

	private void initView() {
		mWebView = (ProgressWebView) this.findViewById(R.id.webview);
		mWebView.setWebViewClient(new WebViewClient() {

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {

				view.loadUrl(url);
				return true;
			}

		});
		TextView title = (TextView) findViewById(R.id.title);
		title.setText("浏览器");
		Button back = (Button) findViewById(R.id.btn_left);
		back.setVisibility(View.VISIBLE);
		back.setOnClickListener(this);
		mWebView.getSettings().setJavaScriptEnabled(true);
//		mWebView.setDownloadListener(new DownloadListener() {
//	            @Override
//	            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
//	                if (url != null && url.startsWith("http://"))
//	                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com/")));
//	            }
//	        });
		mWebView.loadUrl("");
		
		// querySelfInfo();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_left:

			finish();

			break;

		default:
			break;
		}

	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
			mWebView.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	private void startProgressDialog() {
		if (progressDialog == null) {
			progressDialog = CustomProgressDialog.createDialog(this);
			progressDialog.setMessage("正在加载...");
		}

		progressDialog.show();
	}

	private void stopProgressDialog() {
		if (progressDialog != null) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}
}